// 文档相关类型
export interface Document {
  id: string;
  title: string;
  content: string;
  file_path?: string;
  file_type: string;
  file_size: number;
  upload_time: Date;
  user_id?: string;
  status?: 'pending' | 'processing' | 'processed' | 'failed';
  metadata?: Record<string, unknown>;
  created_at: string;
}

// 向量文档类型
export interface VectorDocument {
  id: string;
  document_id: string;
  chunk_index: number;
  content: string;
  embedding: number[];
  metadata: Record<string, unknown>;
}

// 聊天消息类型
export interface ChatMessage {
  id: string;
  session_id: string;
  role: 'user' | 'assistant' | 'system';
  content: string;
  timestamp: string;
  created_at: string;
  updated_at?: string;
  metadata?: {
    rag_results?: unknown[];
    [key: string]: unknown;
  };
}

// 聊天会话类型
export interface ChatSession {
  id: string;
  title: string;
  user_id?: string;
  created_at: string;
  updated_at: string;
  message_count: number;
  messages: ChatMessage[];
  metadata?: Record<string, unknown>;
}

// RAG查询结果类型
export interface RAGResult {
  answer: string;
  sources: {
    document_id: string;
    title: string;
    content: string;
    similarity_score: number;
    chunk_index: number;
  }[];
  query: string;
  timestamp: Date;
}

// 文件上传类型
export interface FileUpload {
  file: File;
  title?: string;
  metadata?: Record<string, unknown>;
}

// API响应类型
export interface ApiResponse<T = unknown> {
  success: boolean;
  data?: T;
  error?: string;
  message?: string;
}

// 搜索参数类型
export interface SearchParams {
  query: string;
  limit?: number;
  threshold?: number;
  filter?: Record<string, unknown>;
}

// 分块配置类型
export interface ChunkConfig {
  chunkSize: number;
  chunkOverlap: number;
  separators?: string[];
}

// 用户类型（如果需要用户系统）
export interface User {
  id: string;
  name: string;
  email: string;
  avatar?: string | null;
  created_at: string;
  updated_at: string;
}

// Zustand状态类型
export interface AppState {
  // 聊天状态
  currentSession: ChatSession | null;
  sessions: ChatSession[];
  isLoading: boolean;

  // 文档状态
  documents: Document[];
  uploadProgress: number;

  // UI状态
  sidebarOpen: boolean;
  theme: 'light' | 'dark';

  // 操作方法
  setCurrentSession: (session: ChatSession | null) => void;
  addMessage: (message: ChatMessage) => void;
  createSession: (title: string) => void;
  deleteSession: (sessionId: string) => void;
  setSidebarOpen: (open: boolean) => void;
  setTheme: (theme: 'light' | 'dark') => void;
  setLoading: (loading: boolean) => void;
  addDocument: (document: Document) => void;
  setUploadProgress: (progress: number) => void;
}
